# 左闭 右闭
class Solution:
    def search(self, nums: List[int], target: int) -> int:
        left = 0
        right = len(nums)-1
        while left <= right: # 由于左右都可取，左边等于右边时还需要进行一次判断；
            middle = (left + right)//2
            if nums[middle] < target:
                left = middle + 1
            elif nums[middle]  > target:
                right = middle - 1
            else:
                return middle
        return -1

# 左闭 右开
class Solution:
    def search(self, nums: List[int], target: int) -> int:
        left = 0
        right = len(nums)
        while left < right: # 左闭右开，当左边等于右边的时候，是不存在的，无需判断
            middle = (left + right)//2
            if nums[middle] < target:
                left = middle + 1
            elif nums[middle]  > target:
                right = middle # 右边的值不取，虽然比较过了，但是不减一
            else:
                return middle
        return -1